package com.easy.controller;

import com.easy.bean.Brand;
import com.easy.service.BrandService;
import com.easy.util.Page;
import com.easy.util.Result;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@RestController
@CrossOrigin//允许跨域访问
@RequestMapping("brand")
public class BrandController {
    @Autowired
    BrandService brandService;

    @PostMapping
    public Result add(@RequestBody Brand brand){
       Object obj= brandService.add(brand);
       return Result.success("添加成功",obj);
    }

    @DeleteMapping("{id}")
    public Result delete(@PathVariable("id") Integer id){
       Object obj= brandService.del(id);
       return Result.success("删除成功",obj);
    }
    @PutMapping
    public Result edit(@RequestBody Brand brand){
        Object obj=brandService.edit(brand);
        return Result.success("编辑信息保存成功",obj);
    }
    @GetMapping("list")
    public Result list(Brand brand){
       Object obj=brandService.all(brand);
        return Result.success(obj);


    }
    @GetMapping("{id}")
    public Result select(@PathVariable("id") Integer id){
        Object obj=brandService.one(id);
        return Result.success(obj);
    }

    @GetMapping("page")
    public Result page(Page page, Brand brand){
        //查询一共少条数据
        //查询当前页要显示的数据
        //将以上数据封装导page对象中
        brandService.page(page,brand);
        //返回page对象
        return Result.success(page);
    }






}
